<extend name="Common/baseView"/>
<block name="css">
    <style>
        .layui-table tr {
            height: 20px;/*数值按需更改*/
        }
    </style>
</block>
<block name="body">
    <div id="adminlistBody" style="padding: 10px;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
            <legend>管理员列表</legend>
        </fieldset>
        <!--产品列表操作-->
        <!--数据接收参考-->
        <form class="layui-form" >
            <div class="layui-form-item" style="padding-left: 40%;">
                <div class="layui-input-inline" style=" width:250px; ">
                    <input type="text" name="search" id="search" lay-verify="" placeholder="请输入名称"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style=" ">
                    <div  class="layui-btn" id="submit" lay-submit lay-filter="search">查找</div>
                </div>
            </div>
        </form>
        <div style="margin-left: 20%">
            <table id="adminList" lay-filter="adminList">
            </table>
        </div>
    </div>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">启用</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a id="use" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">禁用</a>
    </script>

</block>
<block name="js">
    //JavaScript代码区域
    <script>
        $('#adminlist').addClass("layui-this");
        $('#auth').addClass("layui-nav-itemed");
        //    数据表格操作
        layui.use(['table','jquery'], function(){
            var table = layui.table;
            var $ = layui.jquery;

            //监听搜索
            $('#submit').on('click',function () {
                var searchValue = $('#search').val();
                table.render({
                    elem: '#adminList'
                    ,url: '{:U("admin/getAdminList")}' //数据接口
                    ,method:'post'
                    ,where:{search:searchValue}
                    ,page: true //开启分页
                    ,limit:10
                    ,width:840
                    ,cols: [[ //表头
                        {field: 'id', title: 'ID', width:60, sort: true, fixed: 'left'}
                        ,{field: 'name', title: '姓名', width:111}
                        ,{field: 'email', title: '邮箱', width:200}
                        ,{field: 'account', title: '账号', width:120}
                        ,{field:'is_use',title:'状态',width:70}
                        ,{field:'status',title:'身份',width:120}
                        ,{fixed:'right',width:150, align:'center', toolbar: '#barDemo'}
                    ]]
                });
            });


            table.on('tool(adminList)', function(obj){
                var data = obj.data;
                if(obj.event === 'detail'){
                    layer.confirm('是否启用？', function(index){
                        $.ajax({
                            url:"{:U('AdminUp')}",
                            data: 'id='+data.id,
                            method:'post',
                            success:function (res) {
                                if(res){
                                    layer.close(index);
                                    layer.msg('启用成功');
                                    table.render({
                                        elem: '#adminList'
                                        ,url: '{:U("Admin/getAdminList")}' //数据接口
                                        ,method:'post'
                                        ,page: true //开启分页
                                        ,limit:10
                                        ,width:840
                                        ,cols: [[ //表头
                                            {field: 'id', title: 'ID', width:60, sort: true, fixed: 'left'}
                                            ,{field: 'name', title: '姓名', width:111}
                                            ,{field: 'email', title: '邮箱', width:200}
                                            ,{field: 'account', title: '账号', width:120}
                                            ,{field:'is_use',title:'状态',width:70}
                                            ,{field:'status',title:'身份',width:120}
                                            ,{fixed:'right',width:150, align:'center', toolbar: '#barDemo'}
                                        ]]
                                    });
                                }else{
                                    layer.close(index);
                                    layer.msg('启用失败');
                                    layer.msg(res);
                                }
                            }
                        });
                    });
                } else if(obj.event === 'del'){
                    layer.confirm('是否禁用？', function(index){
                        $.ajax({
                            url:"{:U('AdminDown')}",
                            data: 'id='+data.id,
                            method:'post',
                            success:function (res) {
                                if(res){
                                    layer.close(index);
                                    layer.msg('禁用成功');
                                    table.render({
                                        elem: '#adminList'
                                        ,url: '{:U("Admin/getAdminList")}' //数据接口
                                        ,method:'post'
                                        ,page: true //开启分页
                                        ,limit:10
                                        ,width:840
                                        ,cols: [[ //表头
                                            {field: 'id', title: 'ID', width:60, sort: true, fixed: 'left'}
                                            ,{field: 'name', title: '姓名', width:111}
                                            ,{field: 'email', title: '邮箱', width:200}
                                            ,{field: 'account', title: '账号', width:120}
                                            ,{field:'is_use',title:'状态',width:70}
                                            ,{field:'status',title:'身份',width:120}
                                            ,{fixed:'right',width:150, align:'center', toolbar: '#barDemo'}
                                        ]]
                                    });
                                }else{
                                    layer.close(index);
                                    layer.msg('禁用失败');
                                    layer.msg(res);
                                }
                            }
                        });
                    });
                } else if(obj.event === 'edit'){
                    $.ajax({
                        url:"{:U('adminEdit')}",
                        data: 'id='+data.id,
                        method:'post',
                        success:function (res) {
//                            console.log(res);
                            $('#adminlistBody').html(res);
                        }
                    });
                }
            });

            table.render({
                elem: '#adminList'
                ,url: '{:U("Admin/getAdminList")}' //数据接口
                ,method:'post'
                ,page: true //开启分页
                ,limit:10
                ,width:840
                ,cols: [[ //表头
                    {field: 'id', title: 'ID', width:60, sort: true, fixed: 'left'}
                    ,{field: 'name', title: '姓名', width:111}
                    ,{field: 'email', title: '邮箱', width:200}
                    ,{field: 'account', title: '账号', width:120}
                    ,{field:'is_use',title:'状态',width:70}
                    ,{field:'status',title:'身份',width:120}
                    ,{fixed:'right',width:150, align:'center', toolbar: '#barDemo'}
                ]]
            });

        });
    </script>
</block>
